<template>
	<el-form :model="formData" ref="formRef" :rules="formRules" label-width="8rem">
		<el-row type="flex" :gutter="10">
			<!-- <el-col :span="12">
                <el-form-item label="时间区间" prop="daterange">
                    <el-date-picker
                        v-model="formData.daterange"
                        value-format="yyyy-MM-dd"
                        format="yyyy-MM-dd"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间"
                    >
                    </el-date-picker>
                </el-form-item>
            </el-col> -->
			<el-col :span="24">
				<el-form-item label="任务名称" prop="task_name">
					<el-input v-model="formData.task_name" disabled></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="24" v-if="formData.task_type==2">
				<el-form-item label="派发" prop="user_ids">
					<el-select v-model="formData.user_ids" multiple placeholder="请选择">
					    <el-option
					      v-for="item in userlist"
					      :key="item.id"
					      :label="item.truename"
					      :value="item.id">
					    </el-option>
					  </el-select>
				</el-form-item>
			</el-col>
			<el-col :span="24" v-if="formData.task_type==1">
				<el-form-item label="派发" prop="group_id">
					<el-select v-model="formData.group_id"  placeholder="请选择">
					    <el-option
					      v-for="item in classlist"
					      :key="item.id"
					      :label="item.group_name"
					      :value="item.id">
					    </el-option>
					  </el-select>
				</el-form-item>
			</el-col>
			<!-- <el-col :span="12">
				<el-form-item label="客户级别" prop="level_id">
					<el-select v-model="formData.level_id" placeholder="请选择">
						<el-option v-for="item in ranklist" :key="item.id" :label="item.name"
							:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
			</el-col> -->
			
			<el-col :span="24">
				<el-form-item label="任务备注" prop="remark">
					<el-input type="textarea" v-model="formData.remark"></el-input>
				</el-form-item>
			</el-col>
		</el-row>
		<el-row type="flex" justify="center" style="margin-top: 30px;">
			<el-button type="primary" icon="el-icon-check" @click="onConfirm">确认</el-button>
			<el-button type="default" icon="el-icon-close" @click="onCancel">取消</el-button>
		</el-row>
	</el-form>
</template>

<script>
	export default {
		name: "member-search",
		props: {
			formData: {
				type: Object,
				default: () => {}
			},
			userlist:{
				type:Array,
				default: () => []
			},
			classlist:{
				type:Array,
				default: () => []
			}
		},
		data() {
			return {
				formRules: {
					mass_name: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}, ],
					// user_ids:[{required: true,message: '请选择',trigger: 'change'}],
					remark:[{required: true,message: '请输入',trigger: 'blur'}],
				}
			};
		},
		methods: {
			onConfirm() {
				console.log(this.formData)
				if(!this.formData.group_id&&this.formData.task_type==1){
					this.$message('请选择分组')
					return
				}
				if(!this.formData.user_ids&&this.formData.task_type==2){
					this.$message('请选择')
					return
				}
				this.$refs.formRef.validate((valid) => {
					if (valid) {
						
						// alert('submit!');
						console.log(this.formData)
						this.$emit("search", this.formData);
						this.$parent.$emit("update:visible", false);
						this.$refs.formRef.resetFields()
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			onCancel() {
				this.$parent.$emit("update:visible", false);
				this.$refs.formRef.resetFields();
			}
		}
	};
</script>
